<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Caffe: include/caffe/filler.hpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Caffe
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_4b7f3da7c7b4301d805dae0326fb91b7.html">caffe</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">filler.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">// Fillers are random number generators that fills a blob using the specified</span></div><div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment">// algorithm. The expectation is that they are only going to be used during</span></div><div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">// initialization time and will not involve any GPUs.</span></div><div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;</div><div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="preprocessor">#ifndef CAFFE_FILLER_HPP</span></div><div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="preprocessor">#define CAFFE_FILLER_HPP</span></div><div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;</div><div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#include &lt;string&gt;</span></div><div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;</div><div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="preprocessor">#include &quot;caffe/blob.hpp&quot;</span></div><div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &quot;caffe/proto/caffe.pb.h&quot;</span></div><div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#include &quot;caffe/syncedmem.hpp&quot;</span></div><div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="preprocessor">#include &quot;caffe/util/math_functions.hpp&quot;</span></div><div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;</div><div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacecaffe.html">caffe</a> {</div><div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;</div><div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Dtype&gt;</div><div class="line"><a name="l00019"></a><span class="lineno"><a class="line" href="classcaffe_1_1Filler.html">   19</a></span>&#160;<span class="keyword">class </span><a class="code" href="classcaffe_1_1Filler.html">Filler</a> {</div><div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;  <span class="keyword">explicit</span> <a class="code" href="classcaffe_1_1Filler.html">Filler</a>(<span class="keyword">const</span> FillerParameter&amp; param) : filler_param_(param) {}</div><div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;  <span class="keyword">virtual</span> ~<a class="code" href="classcaffe_1_1Filler.html">Filler</a>() {}</div><div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Fill(<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>* blob) = 0;</div><div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160; <span class="keyword">protected</span>:</div><div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;  FillerParameter filler_param_;</div><div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;};  <span class="comment">// class Filler</span></div><div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;</div><div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;</div><div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Dtype&gt;</div><div class="line"><a name="l00031"></a><span class="lineno"><a class="line" href="classcaffe_1_1ConstantFiller.html">   31</a></span>&#160;<span class="keyword">class </span><a class="code" href="classcaffe_1_1ConstantFiller.html">ConstantFiller</a> : <span class="keyword">public</span> <a class="code" href="classcaffe_1_1Filler.html">Filler</a>&lt;Dtype&gt; {</div><div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;  <span class="keyword">explicit</span> <a class="code" href="classcaffe_1_1ConstantFiller.html">ConstantFiller</a>(<span class="keyword">const</span> FillerParameter&amp; param)</div><div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;      : <a class="code" href="classcaffe_1_1Filler.html">Filler&lt;Dtype&gt;</a>(param) {}</div><div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Fill(<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>* blob) {</div><div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;    Dtype* data = blob-&gt;mutable_cpu_data();</div><div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160;    <span class="keyword">const</span> <span class="keywordtype">int</span> count = blob-&gt;count();</div><div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;    <span class="keyword">const</span> Dtype value = this-&gt;filler_param_.value();</div><div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;    CHECK(count);</div><div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; count; ++i) {</div><div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;      data[i] = value;</div><div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    }</div><div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;    CHECK_EQ(this-&gt;filler_param_.sparse(), -1)</div><div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;         &lt;&lt; <span class="stringliteral">&quot;Sparsity not supported by this Filler.&quot;</span>;</div><div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;  }</div><div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;};</div><div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;</div><div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Dtype&gt;</div><div class="line"><a name="l00050"></a><span class="lineno"><a class="line" href="classcaffe_1_1UniformFiller.html">   50</a></span>&#160;<span class="keyword">class </span><a class="code" href="classcaffe_1_1UniformFiller.html">UniformFiller</a> : <span class="keyword">public</span> <a class="code" href="classcaffe_1_1Filler.html">Filler</a>&lt;Dtype&gt; {</div><div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;  <span class="keyword">explicit</span> <a class="code" href="classcaffe_1_1UniformFiller.html">UniformFiller</a>(<span class="keyword">const</span> FillerParameter&amp; param)</div><div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;      : <a class="code" href="classcaffe_1_1Filler.html">Filler&lt;Dtype&gt;</a>(param) {}</div><div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Fill(<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>* blob) {</div><div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;    CHECK(blob-&gt;count());</div><div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;    caffe_rng_uniform&lt;Dtype&gt;(blob-&gt;count(), Dtype(this-&gt;filler_param_.min()),</div><div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;        Dtype(this-&gt;filler_param_.max()), blob-&gt;mutable_cpu_data());</div><div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;    CHECK_EQ(this-&gt;filler_param_.sparse(), -1)</div><div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;         &lt;&lt; <span class="stringliteral">&quot;Sparsity not supported by this Filler.&quot;</span>;</div><div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;  }</div><div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;};</div><div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;</div><div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Dtype&gt;</div><div class="line"><a name="l00065"></a><span class="lineno"><a class="line" href="classcaffe_1_1GaussianFiller.html">   65</a></span>&#160;<span class="keyword">class </span><a class="code" href="classcaffe_1_1GaussianFiller.html">GaussianFiller</a> : <span class="keyword">public</span> <a class="code" href="classcaffe_1_1Filler.html">Filler</a>&lt;Dtype&gt; {</div><div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;  <span class="keyword">explicit</span> <a class="code" href="classcaffe_1_1GaussianFiller.html">GaussianFiller</a>(<span class="keyword">const</span> FillerParameter&amp; param)</div><div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;      : <a class="code" href="classcaffe_1_1Filler.html">Filler&lt;Dtype&gt;</a>(param) {}</div><div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Fill(<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>* blob) {</div><div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;    Dtype* data = blob-&gt;mutable_cpu_data();</div><div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;    CHECK(blob-&gt;count());</div><div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;    caffe_rng_gaussian&lt;Dtype&gt;(blob-&gt;count(), Dtype(this-&gt;filler_param_.mean()),</div><div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;        Dtype(this-&gt;filler_param_.std()), blob-&gt;mutable_cpu_data());</div><div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;    <span class="keywordtype">int</span> sparse = this-&gt;filler_param_.sparse();</div><div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    CHECK_GE(sparse, -1);</div><div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;    <span class="keywordflow">if</span> (sparse &gt;= 0) {</div><div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;      <span class="comment">// Sparse initialization is implemented for &quot;weight&quot; blobs; i.e. matrices.</span></div><div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;      <span class="comment">// These have num == channels == 1; width is number of inputs; height is</span></div><div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;      <span class="comment">// number of outputs.  The &#39;sparse&#39; variable specifies the mean number</span></div><div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;      <span class="comment">// of non-zero input weights for a given output.</span></div><div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;      CHECK_GE(blob-&gt;num_axes(), 1);</div><div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;      <span class="keyword">const</span> <span class="keywordtype">int</span> num_outputs = blob-&gt;shape(0);</div><div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;      Dtype non_zero_probability = Dtype(sparse) / Dtype(num_outputs);</div><div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;      rand_vec_.reset(<span class="keyword">new</span> <a class="code" href="classcaffe_1_1SyncedMemory.html">SyncedMemory</a>(blob-&gt;count() * <span class="keyword">sizeof</span>(int)));</div><div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;      <span class="keywordtype">int</span>* mask = <span class="keyword">reinterpret_cast&lt;</span><span class="keywordtype">int</span>*<span class="keyword">&gt;</span>(rand_vec_-&gt;mutable_cpu_data());</div><div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;      caffe_rng_bernoulli(blob-&gt;count(), non_zero_probability, mask);</div><div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;      <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; blob-&gt;count(); ++i) {</div><div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;        data[i] *= mask[i];</div><div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;      }</div><div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;    }</div><div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;  }</div><div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;</div><div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160; <span class="keyword">protected</span>:</div><div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;  shared_ptr&lt;SyncedMemory&gt; rand_vec_;</div><div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;};</div><div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;</div><div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Dtype&gt;</div><div class="line"><a name="l00101"></a><span class="lineno"><a class="line" href="classcaffe_1_1PositiveUnitballFiller.html">  101</a></span>&#160;<span class="keyword">class </span><a class="code" href="classcaffe_1_1PositiveUnitballFiller.html">PositiveUnitballFiller</a> : <span class="keyword">public</span> <a class="code" href="classcaffe_1_1Filler.html">Filler</a>&lt;Dtype&gt; {</div><div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;  <span class="keyword">explicit</span> <a class="code" href="classcaffe_1_1PositiveUnitballFiller.html">PositiveUnitballFiller</a>(<span class="keyword">const</span> FillerParameter&amp; param)</div><div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;      : <a class="code" href="classcaffe_1_1Filler.html">Filler&lt;Dtype&gt;</a>(param) {}</div><div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Fill(<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>* blob) {</div><div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;    Dtype* data = blob-&gt;mutable_cpu_data();</div><div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;    DCHECK(blob-&gt;count());</div><div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;    caffe_rng_uniform&lt;Dtype&gt;(blob-&gt;count(), 0, 1, blob-&gt;mutable_cpu_data());</div><div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;    <span class="comment">// We expect the filler to not be called very frequently, so we will</span></div><div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;    <span class="comment">// just use a simple implementation</span></div><div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;    <span class="keywordtype">int</span> dim = blob-&gt;count() / blob-&gt;<a class="code" href="classcaffe_1_1Blob.html#a80ed3eddf98ffd408e9a627b1a7c2a9e">num</a>();</div><div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;    CHECK(dim);</div><div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; blob-&gt;<a class="code" href="classcaffe_1_1Blob.html#a80ed3eddf98ffd408e9a627b1a7c2a9e">num</a>(); ++i) {</div><div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;      Dtype sum = 0;</div><div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;      <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j &lt; dim; ++j) {</div><div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;        sum += data[i * dim + j];</div><div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;      }</div><div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;      <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j &lt; dim; ++j) {</div><div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;        data[i * dim + j] /= sum;</div><div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;      }</div><div class="line"><a name="l00121"></a><span class="lineno">  121</span>&#160;    }</div><div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;    CHECK_EQ(this-&gt;filler_param_.sparse(), -1)</div><div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;         &lt;&lt; <span class="stringliteral">&quot;Sparsity not supported by this Filler.&quot;</span>;</div><div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;  }</div><div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;};</div><div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;</div><div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Dtype&gt;</div><div class="line"><a name="l00144"></a><span class="lineno"><a class="line" href="classcaffe_1_1XavierFiller.html">  144</a></span>&#160;<span class="keyword">class </span><a class="code" href="classcaffe_1_1XavierFiller.html">XavierFiller</a> : <span class="keyword">public</span> <a class="code" href="classcaffe_1_1Filler.html">Filler</a>&lt;Dtype&gt; {</div><div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;  <span class="keyword">explicit</span> <a class="code" href="classcaffe_1_1XavierFiller.html">XavierFiller</a>(<span class="keyword">const</span> FillerParameter&amp; param)</div><div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;      : <a class="code" href="classcaffe_1_1Filler.html">Filler&lt;Dtype&gt;</a>(param) {}</div><div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Fill(<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>* blob) {</div><div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;    CHECK(blob-&gt;count());</div><div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;    <span class="keywordtype">int</span> fan_in = blob-&gt;count() / blob-&gt;<a class="code" href="classcaffe_1_1Blob.html#a80ed3eddf98ffd408e9a627b1a7c2a9e">num</a>();</div><div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;    <span class="keywordtype">int</span> fan_out = blob-&gt;count() / blob-&gt;<a class="code" href="classcaffe_1_1Blob.html#ae48c8e9f0a0b66b041e47bf37ed04471">channels</a>();</div><div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;    Dtype n = fan_in;  <span class="comment">// default to fan_in</span></div><div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;    <span class="keywordflow">if</span> (this-&gt;filler_param_.variance_norm() ==</div><div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;        FillerParameter_VarianceNorm_AVERAGE) {</div><div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;      n = (fan_in + fan_out) / Dtype(2);</div><div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (this-&gt;filler_param_.variance_norm() ==</div><div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;        FillerParameter_VarianceNorm_FAN_OUT) {</div><div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;      n = fan_out;</div><div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;    }</div><div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;    Dtype scale = sqrt(Dtype(3) / n);</div><div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;    caffe_rng_uniform&lt;Dtype&gt;(blob-&gt;count(), -scale, scale,</div><div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;        blob-&gt;mutable_cpu_data());</div><div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;    CHECK_EQ(this-&gt;filler_param_.sparse(), -1)</div><div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;         &lt;&lt; <span class="stringliteral">&quot;Sparsity not supported by this Filler.&quot;</span>;</div><div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;  }</div><div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;};</div><div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;</div><div class="line"><a name="l00185"></a><span class="lineno">  185</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Dtype&gt;</div><div class="line"><a name="l00186"></a><span class="lineno"><a class="line" href="classcaffe_1_1MSRAFiller.html">  186</a></span>&#160;<span class="keyword">class </span><a class="code" href="classcaffe_1_1MSRAFiller.html">MSRAFiller</a> : <span class="keyword">public</span> <a class="code" href="classcaffe_1_1Filler.html">Filler</a>&lt;Dtype&gt; {</div><div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;  <span class="keyword">explicit</span> <a class="code" href="classcaffe_1_1MSRAFiller.html">MSRAFiller</a>(<span class="keyword">const</span> FillerParameter&amp; param)</div><div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;      : <a class="code" href="classcaffe_1_1Filler.html">Filler&lt;Dtype&gt;</a>(param) {}</div><div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Fill(<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>* blob) {</div><div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;    CHECK(blob-&gt;count());</div><div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;    <span class="keywordtype">int</span> fan_in = blob-&gt;count() / blob-&gt;<a class="code" href="classcaffe_1_1Blob.html#a80ed3eddf98ffd408e9a627b1a7c2a9e">num</a>();</div><div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;    <span class="keywordtype">int</span> fan_out = blob-&gt;count() / blob-&gt;<a class="code" href="classcaffe_1_1Blob.html#ae48c8e9f0a0b66b041e47bf37ed04471">channels</a>();</div><div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;    Dtype n = fan_in;  <span class="comment">// default to fan_in</span></div><div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;    <span class="keywordflow">if</span> (this-&gt;filler_param_.variance_norm() ==</div><div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;        FillerParameter_VarianceNorm_AVERAGE) {</div><div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;      n = (fan_in + fan_out) / Dtype(2);</div><div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;    } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (this-&gt;filler_param_.variance_norm() ==</div><div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;        FillerParameter_VarianceNorm_FAN_OUT) {</div><div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;      n = fan_out;</div><div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;    }</div><div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;    Dtype std = sqrt(Dtype(2) / n);</div><div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;    caffe_rng_gaussian&lt;Dtype&gt;(blob-&gt;count(), Dtype(0), std,</div><div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;        blob-&gt;mutable_cpu_data());</div><div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;    CHECK_EQ(this-&gt;filler_param_.sparse(), -1)</div><div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;         &lt;&lt; <span class="stringliteral">&quot;Sparsity not supported by this Filler.&quot;</span>;</div><div class="line"><a name="l00207"></a><span class="lineno">  207</span>&#160;  }</div><div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;};</div><div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;</div><div class="line"><a name="l00243"></a><span class="lineno">  243</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Dtype&gt;</div><div class="line"><a name="l00244"></a><span class="lineno"><a class="line" href="classcaffe_1_1BilinearFiller.html">  244</a></span>&#160;<span class="keyword">class </span><a class="code" href="classcaffe_1_1BilinearFiller.html">BilinearFiller</a> : <span class="keyword">public</span> <a class="code" href="classcaffe_1_1Filler.html">Filler</a>&lt;Dtype&gt; {</div><div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160; <span class="keyword">public</span>:</div><div class="line"><a name="l00246"></a><span class="lineno">  246</span>&#160;  <span class="keyword">explicit</span> <a class="code" href="classcaffe_1_1BilinearFiller.html">BilinearFiller</a>(<span class="keyword">const</span> FillerParameter&amp; param)</div><div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;      : <a class="code" href="classcaffe_1_1Filler.html">Filler&lt;Dtype&gt;</a>(param) {}</div><div class="line"><a name="l00248"></a><span class="lineno">  248</span>&#160;  <span class="keyword">virtual</span> <span class="keywordtype">void</span> Fill(<a class="code" href="classcaffe_1_1Blob.html">Blob&lt;Dtype&gt;</a>* blob) {</div><div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160;    CHECK_EQ(blob-&gt;num_axes(), 4) &lt;&lt; <span class="stringliteral">&quot;Blob must be 4 dim.&quot;</span>;</div><div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;    CHECK_EQ(blob-&gt;<a class="code" href="classcaffe_1_1Blob.html#afbdc067c69e6b9bd6880a73c13db2ec6">width</a>(), blob-&gt;<a class="code" href="classcaffe_1_1Blob.html#a18af535af43f4e9f85bd1e520886276f">height</a>()) &lt;&lt; <span class="stringliteral">&quot;Filter must be square&quot;</span>;</div><div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;    Dtype* data = blob-&gt;mutable_cpu_data();</div><div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;    <span class="keywordtype">int</span> f = ceil(blob-&gt;<a class="code" href="classcaffe_1_1Blob.html#afbdc067c69e6b9bd6880a73c13db2ec6">width</a>() / 2.);</div><div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;    <span class="keywordtype">float</span> c = (2 * f - 1 - f % 2) / (2. * f);</div><div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;    <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; blob-&gt;count(); ++i) {</div><div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160;      <span class="keywordtype">float</span> x = i % blob-&gt;<a class="code" href="classcaffe_1_1Blob.html#afbdc067c69e6b9bd6880a73c13db2ec6">width</a>();</div><div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;      <span class="keywordtype">float</span> y = (i / blob-&gt;<a class="code" href="classcaffe_1_1Blob.html#afbdc067c69e6b9bd6880a73c13db2ec6">width</a>()) % blob-&gt;<a class="code" href="classcaffe_1_1Blob.html#a18af535af43f4e9f85bd1e520886276f">height</a>();</div><div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;      data[i] = (1 - fabs(x / f - c)) * (1 - fabs(y / f - c));</div><div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;    }</div><div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;    CHECK_EQ(this-&gt;filler_param_.sparse(), -1)</div><div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;         &lt;&lt; <span class="stringliteral">&quot;Sparsity not supported by this Filler.&quot;</span>;</div><div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160;  }</div><div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;};</div><div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;</div><div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> Dtype&gt;</div><div class="line"><a name="l00271"></a><span class="lineno"><a class="line" href="namespacecaffe.html#a819e1b2fe30b54d6df0fd88e646ec126">  271</a></span>&#160;<a class="code" href="classcaffe_1_1Filler.html">Filler&lt;Dtype&gt;</a>* <a class="code" href="namespacecaffe.html#a819e1b2fe30b54d6df0fd88e646ec126">GetFiller</a>(<span class="keyword">const</span> FillerParameter&amp; param) {</div><div class="line"><a name="l00272"></a><span class="lineno">  272</span>&#160;  <span class="keyword">const</span> std::string&amp; type = param.type();</div><div class="line"><a name="l00273"></a><span class="lineno">  273</span>&#160;  <span class="keywordflow">if</span> (type == <span class="stringliteral">&quot;constant&quot;</span>) {</div><div class="line"><a name="l00274"></a><span class="lineno">  274</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classcaffe_1_1ConstantFiller.html">ConstantFiller&lt;Dtype&gt;</a>(param);</div><div class="line"><a name="l00275"></a><span class="lineno">  275</span>&#160;  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (type == <span class="stringliteral">&quot;gaussian&quot;</span>) {</div><div class="line"><a name="l00276"></a><span class="lineno">  276</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classcaffe_1_1GaussianFiller.html">GaussianFiller&lt;Dtype&gt;</a>(param);</div><div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (type == <span class="stringliteral">&quot;positive_unitball&quot;</span>) {</div><div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classcaffe_1_1PositiveUnitballFiller.html">PositiveUnitballFiller&lt;Dtype&gt;</a>(param);</div><div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (type == <span class="stringliteral">&quot;uniform&quot;</span>) {</div><div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classcaffe_1_1UniformFiller.html">UniformFiller&lt;Dtype&gt;</a>(param);</div><div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (type == <span class="stringliteral">&quot;xavier&quot;</span>) {</div><div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classcaffe_1_1XavierFiller.html">XavierFiller&lt;Dtype&gt;</a>(param);</div><div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (type == <span class="stringliteral">&quot;msra&quot;</span>) {</div><div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classcaffe_1_1MSRAFiller.html">MSRAFiller&lt;Dtype&gt;</a>(param);</div><div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;  } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (type == <span class="stringliteral">&quot;bilinear&quot;</span>) {</div><div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classcaffe_1_1BilinearFiller.html">BilinearFiller&lt;Dtype&gt;</a>(param);</div><div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;  } <span class="keywordflow">else</span> {</div><div class="line"><a name="l00288"></a><span class="lineno">  288</span>&#160;    CHECK(<span class="keyword">false</span>) &lt;&lt; <span class="stringliteral">&quot;Unknown filler name: &quot;</span> &lt;&lt; param.type();</div><div class="line"><a name="l00289"></a><span class="lineno">  289</span>&#160;  }</div><div class="line"><a name="l00290"></a><span class="lineno">  290</span>&#160;  <span class="keywordflow">return</span> (<a class="code" href="classcaffe_1_1Filler.html">Filler&lt;Dtype&gt;</a>*)(NULL);</div><div class="line"><a name="l00291"></a><span class="lineno">  291</span>&#160;}</div><div class="line"><a name="l00292"></a><span class="lineno">  292</span>&#160;</div><div class="line"><a name="l00293"></a><span class="lineno">  293</span>&#160;}  <span class="comment">// namespace caffe</span></div><div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;</div><div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;<span class="preprocessor">#endif  // CAFFE_FILLER_HPP_</span></div><div class="ttc" id="classcaffe_1_1Blob_html_ae48c8e9f0a0b66b041e47bf37ed04471"><div class="ttname"><a href="classcaffe_1_1Blob.html#ae48c8e9f0a0b66b041e47bf37ed04471">caffe::Blob::channels</a></div><div class="ttdeci">int channels() const</div><div class="ttdoc">Deprecated legacy shape accessor channels: use shape(1) instead. </div><div class="ttdef"><b>Definition:</b> blob.hpp:134</div></div>
<div class="ttc" id="classcaffe_1_1Filler_html"><div class="ttname"><a href="classcaffe_1_1Filler.html">caffe::Filler</a></div><div class="ttdoc">Fills a Blob with constant or randomly-generated data. </div><div class="ttdef"><b>Definition:</b> filler.hpp:19</div></div>
<div class="ttc" id="classcaffe_1_1PositiveUnitballFiller_html"><div class="ttname"><a href="classcaffe_1_1PositiveUnitballFiller.html">caffe::PositiveUnitballFiller</a></div><div class="ttdoc">Fills a Blob with values  such that . </div><div class="ttdef"><b>Definition:</b> filler.hpp:101</div></div>
<div class="ttc" id="namespacecaffe_html"><div class="ttname"><a href="namespacecaffe.html">caffe</a></div><div class="ttdoc">A layer factory that allows one to register layers. During runtime, registered layers can be called b...</div><div class="ttdef"><b>Definition:</b> blob.hpp:14</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_a18af535af43f4e9f85bd1e520886276f"><div class="ttname"><a href="classcaffe_1_1Blob.html#a18af535af43f4e9f85bd1e520886276f">caffe::Blob::height</a></div><div class="ttdeci">int height() const</div><div class="ttdoc">Deprecated legacy shape accessor height: use shape(2) instead. </div><div class="ttdef"><b>Definition:</b> blob.hpp:136</div></div>
<div class="ttc" id="classcaffe_1_1BilinearFiller_html"><div class="ttname"><a href="classcaffe_1_1BilinearFiller.html">caffe::BilinearFiller</a></div><div class="ttdoc">Fills a Blob with coefficients for bilinear interpolation. </div><div class="ttdef"><b>Definition:</b> filler.hpp:244</div></div>
<div class="ttc" id="namespacecaffe_html_a819e1b2fe30b54d6df0fd88e646ec126"><div class="ttname"><a href="namespacecaffe.html#a819e1b2fe30b54d6df0fd88e646ec126">caffe::GetFiller</a></div><div class="ttdeci">Filler&lt; Dtype &gt; * GetFiller(const FillerParameter &amp;param)</div><div class="ttdoc">Get a specific filler from the specification given in FillerParameter. </div><div class="ttdef"><b>Definition:</b> filler.hpp:271</div></div>
<div class="ttc" id="classcaffe_1_1XavierFiller_html"><div class="ttname"><a href="classcaffe_1_1XavierFiller.html">caffe::XavierFiller</a></div><div class="ttdoc">Fills a Blob with values  where  is set inversely proportional to number of incoming nodes...</div><div class="ttdef"><b>Definition:</b> filler.hpp:144</div></div>
<div class="ttc" id="classcaffe_1_1UniformFiller_html"><div class="ttname"><a href="classcaffe_1_1UniformFiller.html">caffe::UniformFiller</a></div><div class="ttdoc">Fills a Blob with uniformly distributed values . </div><div class="ttdef"><b>Definition:</b> filler.hpp:50</div></div>
<div class="ttc" id="classcaffe_1_1GaussianFiller_html"><div class="ttname"><a href="classcaffe_1_1GaussianFiller.html">caffe::GaussianFiller</a></div><div class="ttdoc">Fills a Blob with Gaussian-distributed values . </div><div class="ttdef"><b>Definition:</b> filler.hpp:65</div></div>
<div class="ttc" id="classcaffe_1_1SyncedMemory_html"><div class="ttname"><a href="classcaffe_1_1SyncedMemory.html">caffe::SyncedMemory</a></div><div class="ttdoc">Manages memory allocation and synchronization between the host (CPU) and device (GPU). </div><div class="ttdef"><b>Definition:</b> syncedmem.hpp:57</div></div>
<div class="ttc" id="classcaffe_1_1MSRAFiller_html"><div class="ttname"><a href="classcaffe_1_1MSRAFiller.html">caffe::MSRAFiller</a></div><div class="ttdoc">Fills a Blob with values  where  is set inversely proportional to number of incoming nodes...</div><div class="ttdef"><b>Definition:</b> filler.hpp:186</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_a80ed3eddf98ffd408e9a627b1a7c2a9e"><div class="ttname"><a href="classcaffe_1_1Blob.html#a80ed3eddf98ffd408e9a627b1a7c2a9e">caffe::Blob::num</a></div><div class="ttdeci">int num() const</div><div class="ttdoc">Deprecated legacy shape accessor num: use shape(0) instead. </div><div class="ttdef"><b>Definition:</b> blob.hpp:132</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html_afbdc067c69e6b9bd6880a73c13db2ec6"><div class="ttname"><a href="classcaffe_1_1Blob.html#afbdc067c69e6b9bd6880a73c13db2ec6">caffe::Blob::width</a></div><div class="ttdeci">int width() const</div><div class="ttdoc">Deprecated legacy shape accessor width: use shape(3) instead. </div><div class="ttdef"><b>Definition:</b> blob.hpp:138</div></div>
<div class="ttc" id="classcaffe_1_1ConstantFiller_html"><div class="ttname"><a href="classcaffe_1_1ConstantFiller.html">caffe::ConstantFiller</a></div><div class="ttdoc">Fills a Blob with constant values . </div><div class="ttdef"><b>Definition:</b> filler.hpp:31</div></div>
<div class="ttc" id="classcaffe_1_1Blob_html"><div class="ttname"><a href="classcaffe_1_1Blob.html">caffe::Blob</a></div><div class="ttdoc">A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers...</div><div class="ttdef"><b>Definition:</b> blob.hpp:24</div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Thu Aug 3 2017 23:11:19 for Caffe by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
</body>
</html>
